package com.pet.server.ext.action.user;

import java.util.List;

import com.pet.server.ext.ActionBase;
import com.pet.server.ext.ApiError;
import com.pet.server.ext.BeanToJson;
import com.pet.server.ext.Result;
import com.pet.server.ext.constants.BaseAttribute;
import com.pet.server.ext.data.Image;
import com.pet.server.ext.data.PetMissing;
import com.pet.server.ext.data.UserInfo;
import com.pet.server.ext.service.UserService;
import com.pet.server.ext.util.NumberUtil;
import com.pet.server.ext.util.Parameters;
import com.pet.server.ext.util.StringUtil;

public class Profile extends ActionBase{
	public Integer  user_id;
	
	public Profile(){
		 needCheckAuth =false;
	}
	
	@Override
	public void initParameters(Parameters params) throws ApiError {	
		user_id = NumberUtil.getInteger(params.getFieldValue("user_id"));
		if(StringUtil.isEmpty(user_id)){
			throw ApiError.Type.INVALID_PARAM.toException();
		}
	}
	
	@Override
	public Result invokeService() throws ApiError {
		UserService userService = new UserService();
		UserInfo u = userService.findUserInfoById(user_id);
		if(null==u){
			throw ApiError.Type.LOGIC_ERROR.toException("用户信息不存在!");
		}
		data.put("nick_name", u.nick_name);
		data.put("user_id", u.user_id);
		data.put("user_type", u.user_type);
		data.put("user_name", u.user_name);
		data.put("ico_path", u.ico_path);
		data.put("background", u.background);
		data.put("sex", "");
		data.put("phone_number", u.phone_number);
		Result result = new Result();
		result.put("data", data);
	    return result;
	}

}
